/**
 * 	字典
 *      let dict = new Dictionary<string,string>();
 *		dict.set('mytest','HAHA');
 *		dict.set('utest','BOBO');
 *		dict.delete('mytest'); //return item's [mytest] value : 'HAHA'
 *		dict.getWithComponent('mytest');//null
 *		dict.getWithComponent('');//null
 *		dict.getWithComponent('utest');//"BOBO"
 */
export class Dictionary<TypeKeyT, TypeValueT>
{
	private _typeKeyList: TypeKeyT[] = new Array<TypeKeyT>();
	private _typeValueList: TypeValueT[] = new Array<TypeValueT>();

	public set(key: TypeKeyT, value: TypeValueT): void {
		let index = this._typeKeyList.indexOf(key);
		if (index == -1) {
			this._typeKeyList.push(key);
			index = this._typeKeyList.indexOf(key);
		}
		this._typeValueList[index] = value;
	}

	public get(key: TypeKeyT): TypeValueT {
		let index = this._typeKeyList.indexOf(key);
		if (index != -1) {
			return this._typeValueList[index];
		}
		return null;
	}

	public delete(key: TypeKeyT): TypeValueT {
		let index = this._typeKeyList.indexOf(key);
		if (index != -1) {
			this._typeKeyList.splice(index, 1);
			let deleteList = this._typeValueList.splice(index, 1);
			return deleteList[0];
		}
		return null;
	}

	public clear(): void {
		for (let k = this._typeKeyList.length - 1; k >= 0; --k) {
			this.delete(this._typeKeyList[k]);
		}
	}

	public containsKey(key: TypeKeyT): boolean {
		if (this._typeKeyList.indexOf(key) >= 0) {
			return true;
		}
		return false;
	}

	public getKeyList(): TypeKeyT[] {
		return this._typeKeyList;
	}

	public getValueList(): any[] {
		return this._typeValueList;
	}

	public length(): number {
		return this._typeKeyList.length;
	}
}